<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
        <p>Todo list</p>
        <p>总任务：4个，还有2个未完成</p>
        <input type="text" v-model.trim="thing" @keyup.enter="add">
        <button @click="add">添加</button>
        <p>待办事项</p>
        <ul>
            <li v-for="(item, index) in todoList" :key="index">
                <span>{{item}}</span>
                <button @click="del(index)">del</button>
            </li>
        </ul>
        <p>完成事项</p>
        <ul>
            <li v-for="(item, index) in doneList" :key="index+'done'">
                <span>{{item}}</span>
            </li>
        </ul>
    </div>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                thing: '', // 待完成事项
                todoList: [], // 待完成的数组
                doneList: [] // 已完成的数组
            },
            methods: {
                // 添加待办事项
                add() {
                    if(this.thing) {
                        this.todoList.push(this.thing)
                    }
                    // 置空输入框
                    this.thing = '';
                },
                // 完成事项
                del(index) {
                    this.doneList.push(this.todoList[index]);
                    // 根据下标删除数组项--从index这个位置开始删除，删除长度是1
                    this.todoList.splice(index, 1);
                }
            }
        })
    </script>
</body>
</html>